class HouseItem:
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return ("%s 占地 %.2f" % (self.name, self.area))


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area
        self.item_list = []

    def __str__(self):
        return ("户型：%s\n总面积：%s\n剩余面积：%s\n家具：%s"
                % (self.house_type, self.area, self.free_area, self.item_list))

    def add_item(self, item:HouseItem):
        print("添加 %s" % item.name)
        if item.area > self.free_area:
            print("%s 的面积太大了，无法添加" % item.name)
            return
        self.item_list.append(item.name)
        self.free_area -= item.area

if __name__ == '__main__':
    # 1.txt. 创建家具
    bed = HouseItem("席梦思", 4)
    chest = HouseItem("衣柜", 2)
    table = HouseItem("餐桌", 1.5)
    print(bed)
    print(chest)
    print(table)
    print("-" * 20)

    # 2. 创建房子对象
    my_home = House("两室一厅", 60)
    print(my_home)
    my_home.add_item(bed)
    print("-" * 20)
    print(my_home)
    my_home.add_item(chest)
    print("-" * 20)
    print(my_home)
    my_home.add_item(table)
    print("-" * 20)
    print(my_home)
